// POST 请求示例 - 处理登录
export default defineEventHandler(async (event) => {
  // 读取请求体
  const body = await readBody(event)
  
  try {
    // 调用真实的后端登录接口
    const backendUrl = 'https://your-backend-api.com/auth/login'
    const response = await $fetch(backendUrl, {
      method: 'POST',
      headers: {
        'Content-Type': 'application/json',
        // 可以添加其他 header
      },
      body: {
        username: body.username,
        password: body.password
      }
    })
    
    // 设置 cookie
    // setCookie(event, 'auth-token', response.token, {
    //   httpOnly: true,
    //   secure: true,
    //   maxAge: 60 * 60 * 24 * 7 // 7天
    // })
    
    return {
      success: true,
      message: '登录成功',
      // data: response
    }
  } catch (error) {
    throw createError({
      statusCode: 401,
      message: '登录失败'
    })
  }
})

